from contextlib import contextmanager
import xlwings as xw


@contextmanager
def open_sht(file_name):
    try:
        app = xw.App(visible=False, add_book=False)
        excel_client = app.books.open(file_name)
        sht = excel_client.sheets["Sheet1"]
        yield sht
    finally:
        excel_client.save()
        excel_client.close()
        app.quit()


def get_col(col_idx):
    epoch = col_idx // 26
    col_name = chr(ord("a") + col_idx % 26)
    if epoch > 0:
        col_name = chr(ord("a") - 1 + epoch) + col_name
    return col_name


def process_logger(func):
    def wrapper(*args, **kwargs):
        print("Processing:", func.__name__)
        return func(*args, **kwargs)

    return wrapper